(function () {
    //获取显示页面数据 服务器分页
    var serverData = {};
    var	serverTable;
    jQuery(document).ready(function () {
        serverTable = jQuery('#dataTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/paySchedule/getpage',
                "data": function (d) {
                    return $.extend({}, d, serverData);
                }
            },
            columns: [
                {
                    data: null
                },
                {
                    data: null,
                    defaultContent: "",
                    render: function (data, type, full, meta) {
                        var id=data.contractId
                        var operate ='<input type="checkbox" class="checkchild">';
                        return operate;
                    }
                },
                {
                    data: 'supplierCode',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'projectName',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 15) ? '<font title="'+data+'">'+data.substring(0,15)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'orderUnit',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 15) ? '<font title="'+data+'">'+data.substring(0,15)+'...'+'</font>' : data;
						}
					}
                },
                {
                    data: 'totalSum'
                },
                {
                    data: 'dutyOfficer'
                },
                {
                    data: 'signedDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY-MM-DD');
                        else
                            return '';
                    }
                },
            ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    });
    //编辑合同计划
    jQuery('.editBtn').on('click', function () {
        var selects=getSelect("#dataTable",1);
        if(selects.length>1){
            $.springLemonDialog({
                content: '只能编辑一条记录',// 确认文本
                clickButton: function (sender, modal, index) {// 按钮事件处理
                    $(this).closeDialog(modal);
                }
            });
        }
        else if(selects.length==0){
            $.springLemonDialog({
                content: '请选择要编辑的记录',// 确认文本
                clickButton: function (sender, modal, index) {// 按钮事件处理
                    $(this).closeDialog(modal);
                }
            });
        }else if(selects.length==1){
            var id=selects[0].contractId;
            var contractType=selects[0].contractType;
            window.location = window.rootPath+'/ui/paySchedule/paymentInitial/' + id+'/'+contractType;
        }
    });
    //查询
    jQuery('.searchBtn').on('click',function(){
        serverData.key=jQuery('#search').val();
        serverTable.draw();
    })
    //撤销查询
    jQuery('.resetBtn').on("click",function()
    {
        jQuery('#search').val('');
        serverData.key ='';
        serverTable.draw();
    });
})();